package com.global.college.utils;

import android.util.Log;
import android.widget.TextView;


import com.global.college.R;

import java.io.File;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符处理工具
 */
public class StringUtils {

    public static final String TAG = "StringUtil";
    private static String currentString = "";
    public static final int PRICE_FORMAT_DEFAULT = 0;
    public static final int PRICE_FORMAT_PREFIX = 1;
    public static final int PRICE_FORMAT_SUFFIX = 2;
    public static final int PRICE_FORMAT_PREFIX_WITH_BLANK = 3;
    public static final int PRICE_FORMAT_SUFFIX_WITH_BLANK = 4;
    public static final String[] PRICE_FORMATS = {"", "¥", "" + getString(R.string.yuan), "¥ ", " " + getString(R.string.yuan)};
    public static final String URL_PREFIX = "http://";
    public static final String URL_PREFIXs = "https://";

    /**
     * 判断字符串是否有值，如果为null或者是空字符串或者只有空格或者为"null"字符串，则返回true，否则则返回false
     */
    public static boolean isEmpty(String value) {
        if (value != null && !"".equalsIgnoreCase(value.trim()) && !"null".equalsIgnoreCase(value.trim())) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 判断两字符串是否相等
     *
     * @param a 待校验字符串a
     * @param b 待校验字符串b
     * @return @return {@code true}: 相等<br>
     * {@code false}: 不相等
     */
    public static boolean equals(CharSequence a, CharSequence b) {
        if (a == b)
            return true;
        int length;
        if (a != null && b != null && (length = a.length()) == b.length()) {
            if (a instanceof String && b instanceof String) {
                return a.equals(b);
            } else {
                for (int i = 0; i < length; i++) {
                    if (a.charAt(i) != b.charAt(i))
                        return false;
                }
                return true;
            }
        }
        return false;
    }

    /**
     * 判断两字符串是否不相等
     *
     * @param a 待校验字符串a
     * @param b 待校验字符串b
     * @return @return {@code true}: 不相等<br>
     * {@code false}: 相等
     */
    public static boolean isNotEquals(CharSequence a, CharSequence b) {
        if (a == b)
            return false;
        int length;
        if (a != null && b != null && (length = a.length()) == b.length()) {
            if (a instanceof String && b instanceof String) {
                return a.equals(b);
            } else {
                for (int i = 0; i < length; i++) {
                    if (a.charAt(i) == b.charAt(i))
                        return false;
                }
                return false;
            }
        }
        return true;
    }

    /**
     * 获取刚传入处理后的string
     *
     * @return
     * @must 上个影响currentString的方法 和 这个方法都应该在同一线程中，否则返回值可能不对
     */
    public static String getCurrentString() {
        return currentString == null ? "" : currentString;
    }

    // 获取string,为null时返回"" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /**
     * 获取string,为null则返回""
     *
     * @param tv
     * @return
     */
    public static String getString(TextView tv) {
        if (tv == null || tv.getText() == null) {
            return "";
        }
        return getString(tv.getText().toString());
    }

    /**
     * 获取string,为null则返回""
     *
     * @param object
     * @return
     */
    public static String getString(Object object) {
        return object == null ? "" : getString(String.valueOf(object));
    }

    /**
     * 获取string,为null则返回""
     *
     * @param cs
     * @return
     */
    public static String getString(CharSequence cs) {
        return cs == null ? "" : getString(cs.toString());
    }

    /**
     * 获取string,为null则返回""
     *
     * @param s
     * @return
     */
    public static String getString(String s) {
        return s == null ? "" : s;
    }

    // 获取string,为null时返回"" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    // 获取去掉前后空格后的string<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /**
     * 获取去掉前后空格后的string,为null则返回""
     *
     * @param tv
     * @return
     */
    public static String getTrimedString(TextView tv) {
        return getTrimedString(getString(tv));
    }

    /**
     * 获取去掉前后空格后的string,为null则返回""
     *
     * @param object
     * @return
     */
    public static String getTrimedString(Object object) {
        return getTrimedString(getString(object));
    }

    /**
     * 获取去掉前后空格后的string,为null则返回""
     *
     * @param cs
     * @return
     */
    public static String getTrimedString(CharSequence cs) {
        return getTrimedString(getString(cs));
    }

    /**
     * 获取去掉前后空格后的string,为null则返回""
     *
     * @param s
     * @return
     */
    public static String getTrimedString(String s) {
        return getString(s).trim();
    }

    // 获取去掉前后空格后的string>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    // 获取去掉所有空格后的string <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /**
     * 获取去掉所有空格后的string,为null则返回""
     *
     * @param tv
     * @return
     */
    public static String getNoBlankString(TextView tv) {
        return getNoBlankString(getString(tv));
    }

    /**
     * 获取去掉所有空格后的string,为null则返回""
     *
     * @param object
     * @return
     */
    public static String getNoBlankString(Object object) {
        return getNoBlankString(getString(object));
    }

    /**
     * 获取去掉所有空格后的string,为null则返回""
     *
     * @param cs
     * @return
     */
    public static String getNoBlankString(CharSequence cs) {
        return getNoBlankString(getString(cs));
    }

    /**
     * 获取去掉所有空格后的string,为null则返回""
     *
     * @param s
     * @return
     */
    public static String getNoBlankString(String s) {
        return getString(s).replaceAll(" ", "");
    }

    // 获取去掉所有空格后的string >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    // 获取string的长度<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /**
     * 获取string的长度,为null则返回0
     *
     * @param tv
     * @param trim
     * @return
     */
    public static int getLength(TextView tv, boolean trim) {
        return getLength(getString(tv), trim);
    }

    /**
     * 获取string的长度,为null则返回0
     *
     * @param object
     * @param trim
     * @return
     */
    public static int getLength(Object object, boolean trim) {
        return getLength(getString(object), trim);
    }

    /**
     * 获取string的长度,为null则返回0
     *
     * @param cs
     * @param trim
     * @return
     */
    public static int getLength(CharSequence cs, boolean trim) {
        return getLength(getString(cs), trim);
    }

    /**
     * 获取string的长度,为null则返回0
     *
     * @param s
     * @param trim
     * @return
     */
    public static int getLength(String s, boolean trim) {
        s = trim ? getTrimedString(s) : s;
        return getString(s).length();
    }

    // 获取string的长度>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    // 判断字符是否非空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /**
     * 判断字符是否非空
     *
     * @param tv
     * @param trim
     * @return
     */
    public static boolean isNotEmpty(TextView tv, boolean trim) {
        return isNotEmpty(getString(tv), trim);
    }

    /**
     * 判断字符是否非空
     *
     * @param object
     * @param trim
     * @return
     */
    public static boolean isNotEmpty(Object object, boolean trim) {
        return isNotEmpty(getString(object), trim);
    }

    /**
     * 判断字符是否非空
     *
     * @param cs
     * @param trim
     * @return
     */
    public static boolean isNotEmpty(CharSequence cs, boolean trim) {
        return isNotEmpty(getString(cs), trim);
    }

    /**
     * 判断字符是否非空
     *
     * @param s
     * @param trim
     * @return
     */
    public static boolean isNotEmpty(String s, boolean trim) {
        // Log.i(TAG, "getTrimedString s = " + s);
        if (s == null) {
            return false;
        }
        if (trim) {
            s = s.trim();
        }
        if (s.length() <= 0) {
            return false;
        }

        currentString = s;

        return true;
    }

    // 判断字符是否非空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    // 判断字符类型 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    // 判断手机格式是否正确
    public static boolean isPhone(String phone) {
        if (isNotEmpty(phone, true) == false) {
            return false;
        }

        String check = "^(((13[0-9])|(14[0-9])|(15([0-9]))|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\\d{8})$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(phone);
        return matcher.matches();
    }

    // 判断email格式是否正确
    public static boolean isEmail(String email) {
        if (isNotEmpty(email, true) == false) {
            return false;
        }

        String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
        Pattern p = Pattern.compile(str);

        currentString = email;

        return p.matcher(email).matches();
    }

    // 判断是否全是数字
    public static boolean isNumber(String number) {
        if (isNotEmpty(number, true) == false) {
            return false;
        }

        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(number);
        if (!isNum.matches()) {
            return false;
        }

        currentString = number;

        return true;
    }

    /**
     * 判断字符类型是否是号码或字母
     *
     * @param inputed
     * @return
     */
    public static boolean isNumberOrAlpha(String inputed) {
        if (inputed == null) {
            Log.e(TAG, "isNumberOrAlpha  inputed == null >> return false;");
            return false;
        }
        Pattern pNumber = Pattern.compile("[0-9]*");
        Matcher mNumber;
        Pattern pAlpha = Pattern.compile("[a-zA-Z]");
        Matcher mAlpha;
        for (int i = 0; i < inputed.length(); i++) {
            mNumber = pNumber.matcher(inputed.substring(i, i + 1));
            mAlpha = pAlpha.matcher(inputed.substring(i, i + 1));
            if (!mNumber.matches() && !mAlpha.matches()) {
                return false;
            }
        }

        currentString = inputed;
        return true;
    }

    /**
     * 判断字符类型是否是身份证号
     *
     * @param idCard
     * @return
     */
    public static boolean isIDCard(String idCard) {
        if (isNotEmpty(idCard, true) == false) {
            return false;
        }
        String check_18 = "^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
       // String check_15 = "^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}[0-9Xx]$";
        Pattern regex;
//        if (StringUtils.getLength(idCard,true) == 15){
//            regex = Pattern.compile(check_15);
//        }else
        if (StringUtils.getLength(idCard,true) == 18){
            regex = Pattern.compile(check_18);
        }else {
            return false;
        }
        Matcher matcher = regex.matcher(idCard);
        return matcher.matches();
    }


    /**
     * 判断字符类型是否是网址
     *
     * @param url
     * @return
     */
    public static boolean isUrl(String url) {
        if (isNotEmpty(url, true) == false) {
            return false;
        } else if (!url.startsWith(URL_PREFIX) && !url.startsWith(URL_PREFIXs)) {
            return false;
        }

        currentString = url;
        return true;
    }

    public static final String FILE_PATH_PREFIX = "file://";

    /**
     * 判断文件路径是否存在
     *
     * @param path
     * @return
     */
    public static boolean isFilePathExist(String path) {
        return StringUtils.isFilePath(path) && new File(path).exists();
    }

    /**
     * 判断字符类型是否是路径
     *
     * @param path
     * @return
     */
    public static boolean isFilePath(String path) {
        if (isNotEmpty(path, true) == false) {
            return false;
        }

        if (!path.contains(".") || path.endsWith(".")) {
            return false;
        }

        currentString = path;

        return true;
    }
    // 判断字符类型 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    // 提取特殊字符<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /**
     * 去掉string内所有非数字类型字符
     *
     * @param tv
     * @return
     */
    public static String getNumber(TextView tv) {
        return getNumber(getString(tv));
    }

    /**
     * 去掉string内所有非数字类型字符
     *
     * @param object
     * @return
     */
    public static String getNumber(Object object) {
        return getNumber(getString(object));
    }

    /**
     * 去掉string内所有非数字类型字符
     *
     * @param cs
     * @return
     */
    public static String getNumber(CharSequence cs) {
        return getNumber(getString(cs));
    }

    /**
     * 去掉string内所有非数字类型字符
     *
     * @param s
     * @return
     */
    public static String getNumber(String s) {
        if (isNotEmpty(s, true) == false) {
            return "";
        }

        String numberString = "";
        String single;
        for (int i = 0; i < s.length(); i++) {
            single = s.substring(i, i + 1);
            if (isNumber(single)) {
                numberString += single;
            }
        }

        return numberString;
    }

    // 提取特殊字符>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    // 校正（自动补全等）字符串<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    /**
     * 获取网址，自动补全
     *
     * @param tv
     * @return
     */
    public static String getCorrectUrl(TextView tv) {
        return getCorrectUrl(getString(tv));
    }

    /**
     * 获取网址，自动补全
     *
     * @param url
     * @return
     */
    public static String getCorrectUrl(String url) {
        Log.i(TAG, "getCorrectUrl : \n" + url);
        if (isNotEmpty(url, true) == false) {
            return "";
        }

        if (!url.endsWith("/") && !url.endsWith(".html")) {
            url = url + "/";
        }

        if (isUrl(url) == false) {
            return URL_PREFIX + url;
        }
        return url;
    }

    /**
     * 获取去掉所有 空格 、"-" 、"+86" 后的phone
     *
     * @param tv
     * @return
     */
    public static String getCorrectPhone(TextView tv) {
        return getCorrectPhone(getString(tv));
    }

    /**
     * 获取去掉所有 空格 、"-" 、"+86" 后的phone
     *
     * @param phone
     * @return
     */
    public static String getCorrectPhone(String phone) {
        if (isNotEmpty(phone, true) == false) {
            return "";
        }

        phone = getNoBlankString(phone);
        phone = phone.replaceAll("-", "");
        if (phone.startsWith("+86")) {
            phone = phone.substring(3);
        } else if (phone.startsWith("12953")) {
            phone = phone.substring(5);
        }
        return phone;
    }

    /**
     * 获取邮箱，自动补全
     *
     * @param tv
     * @return
     */
    public static String getCorrectEmail(TextView tv) {
        return getCorrectEmail(getString(tv));
    }

    /**
     * 获取邮箱，自动补全
     *
     * @param email
     * @return
     */
    public static String getCorrectEmail(String email) {
        if (isNotEmpty(email, true) == false) {
            return "";
        }

        email = getNoBlankString(email);
        if (isEmail(email) == false && !email.endsWith(".com")) {
            email += ".com";
        }

        return email;
    }



    /**
     * 获取价格，保留两位小数
     *
     * @param price
     * @return
     */
    public static String getPrice(String price) {
        return getPrice(price, PRICE_FORMAT_DEFAULT);
    }

    /**
     * 获取价格，保留两位小数
     *
     * @param price
     * @param formatType 添加单位（元）
     * @return
     */
    public static String getPrice(String price, int formatType) {
        if (isNotEmpty(price, true) == false) {
            return getPrice(0, formatType);
        }

        // 单独写到getCorrectPrice? <<<<<<<<<<<<<<<<<<<<<<
        String correctPrice = "";
        String s;
        for (int i = 0; i < price.length(); i++) {
            s = price.substring(i, i + 1);
            if (".".equals(s) || isNumber(s)) {
                correctPrice += s;
            }
        }
        // 单独写到getCorrectPrice? >>>>>>>>>>>>>>>>>>>>>>

        Log.i(TAG, "getPrice  <<<<<<<<<<<<<<<<<< correctPrice =  " + correctPrice);
        if (correctPrice.contains(".")) {
            // if (correctPrice.startsWith(".")) {
            // correctPrice = 0 + correctPrice;
            // }
            if (correctPrice.endsWith(".")) {
                correctPrice = correctPrice.replaceAll(".", "");
            }
        }

        Log.i(TAG, "getPrice correctPrice =  " + correctPrice + " >>>>>>>>>>>>>>>>");
        return isNotEmpty(correctPrice, true) ? getPrice(new BigDecimal(0 + correctPrice), formatType)
                : getPrice(0, formatType);
    }

    /**
     * 获取价格，保留两位小数
     *
     * @param price
     * @return
     */
    public static String getPrice(BigDecimal price) {
        return getPrice(price, PRICE_FORMAT_DEFAULT);
    }

    /**
     * 获取价格，保留两位小数
     *
     * @param price
     * @return
     */
    public static String getPrice(double price) {
        return getPrice(price, PRICE_FORMAT_DEFAULT);
    }

    /**
     * 获取价格，保留两位小数
     *
     * @param price
     * @param formatType 添加单位（元）
     * @return
     */
    public static String getPrice(BigDecimal price, int formatType) {
        return getPrice(price == null ? 0 : price.doubleValue(), formatType);
    }

    /**
     * 获取价格，保留两位小数
     *
     * @param price
     * @param formatType 添加单位（元）
     * @return
     */
    public static String getPrice(double price, int formatType) {
        String s = new DecimalFormat("#########0.00").format(price);
        switch (formatType) {
            case PRICE_FORMAT_PREFIX:
                return PRICE_FORMATS[PRICE_FORMAT_PREFIX] + s;
            case PRICE_FORMAT_SUFFIX:
                return s + PRICE_FORMATS[PRICE_FORMAT_SUFFIX];
            case PRICE_FORMAT_PREFIX_WITH_BLANK:
                return PRICE_FORMATS[PRICE_FORMAT_PREFIX_WITH_BLANK] + s;
            case PRICE_FORMAT_SUFFIX_WITH_BLANK:
                return s + PRICE_FORMATS[PRICE_FORMAT_SUFFIX_WITH_BLANK];
            default:
                return s;
        }
    }

    public static String getPrice2(String price) {
        String s = "0.00";
        try {
            if (StringUtils.isEmpty(price)){
                price = "0.00";
            }
            double money = Double.valueOf(price);
            DecimalFormat    df   = new DecimalFormat("######0.00");
            s = df.format(money);
        }catch (Exception e){
            e.printStackTrace();
        }
        return s;
    }

    /**
     * 切割字符串，存到数组之中
     *
     * @param value 切割对象
     * @param //array 存取切割对象
     * @param flag  切割标志
     * @return
     */
    public static String[] doSplit(String value, String flag) {
        String[] array = null;
        if (isNotEmpty(value, true)) {
            array = value.split(flag);
        }
        return array;
    }


    // 校正（自动补全等）字符串>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    /**
     * 判断字符串是否为null或全为空格
     *
     * @param s 待校验字符串
     * @return {@code true}: null或全空格<br> {@code false}: 不为null且不全空格
     */
    public static boolean isSpace(String s) {
        return (s == null || s.trim().length() == 0);
    }

    /**
     * 获取随机整数
     */

    private static final Random RANDOM = new Random();

    public static int rondomRange(int max, int min) {
        return RANDOM.nextInt(max)
                % (max - min + 1) + min;
    }


    //金额验证
    public static boolean isMoneyNumber(String str)
    {
        Pattern pattern= Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$"); // 判断小数点后2位的数字的正则表达式
        Matcher match=pattern.matcher(str);
        if(match.matches()==false)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    /**
     * 中文名字：只展示姓名第一个字
        * 身份证号：年月日脱敏，前6后4不脱敏
        * 手机号：前三后四不脱敏，中间脱敏
        * 银行卡：前6位和后4位不脱敏，中间脱敏
        */
    public static String replaceStr(String param) {
        int len=param.length();
        if(isContainChinese(param)){
            return param.replaceAll("(.{1})(.*)(.{0})", "$1" + "**" + "$3");
        }
        return param.replaceAll("(.{"+(len<12?3:6)+"})(.*)(.{4})", "$1" +"****" + "$3");
    }

    /**
     * @description:
     * @return: 判断字符串中是否含中文
     * @author: Administrator
     * @date: 2019/10/4
     */
    public static boolean isContainChinese(String str) {
        Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
        Matcher m = p.matcher(str);
        if (m.find()) {
            return true;
        }
        return false;
    }

    /**
     * 校验银行卡卡号(比较算出的校验位和卡号里的校验位)
     * @param cardId
     * @return
     */
    public static boolean checkBankCard(String cardId) {
        char bit = getBankCardCheckCode(cardId.substring(0, cardId.length() - 1));
        return cardId.charAt(cardId.length() - 1) == bit;
    }

    /**
     * 用不含校验位的银行卡卡号，采用 Luhm 校验算法获得校验位(卡号最后一位为校验位)
     * @param nonCheckCodeCardId
     * @return
     */
    public static char getBankCardCheckCode(String nonCheckCodeCardId) {
        if(nonCheckCodeCardId == null || nonCheckCodeCardId.trim().length() == 0
                || !nonCheckCodeCardId.matches("\\d+")) {
            throw new IllegalArgumentException("Bank card code must be number!");
        }
        char[] chs = nonCheckCodeCardId.trim().toCharArray();
        int luhmSum = 0;
        for(int i = chs.length - 1, j = 0; i >= 0; i--, j++) {
            int k = chs[i] - '0';
            if(j % 2 == 0) {
                k *= 2;
                k = k / 10 + k % 10;
            }
            luhmSum += k;
        }
        return (luhmSum % 10 == 0) ? '0' : (char)((10 - luhmSum % 10) + '0');
    }

    /**
     * 截取固定长度的字符串
     * @param src
     * @param length
     * @return
     */
    public static String getSubString(String src,int length)
    {
        String ititle=src;
        char[] ct=ititle.toCharArray();
        int sum=0;
        for(int c=0;c<ct.length;c++)
        {
            if(Character.getType(ct[c])==5)
                sum+=2;
            else
                sum+=1;
        }
        if(sum>length)
        {
            char[] temp=new char[length];
            int t=0;
            for(int c=0;c<length-1;t++)
            {
                if(Character.getType(ct[t])==5)
                {
                    temp[t]=ct[t];
                    c+=2;
                }
                else
                {
                    temp[t]=ct[t];
                    c+=1;
                }
            }
            ititle=new String(temp);
            return ititle+"...";
        }
        else
            return src;
    }

    public static String ToDBC(String input) {
        char[] c = input.toCharArray();
        for (int i = 0; i< c.length; i++) {
            if (c[i] == 12288) {
                c[i] = (char) 32;
                continue;
            }if (c[i]> 65280&& c[i]< 65375)
                c[i] = (char) (c[i] - 65248);
        }
        return new String(c);
    }

    /**
     * string 转成 string[]
     * @param fields
     * @return
     */
    public static String[] stringInArrays(String fields) {
        String[] field = null;
        if (fields != null && fields.length() > 0) {
            field = fields.split(",");
            String first = field[0];
            field[0] = first.substring(first.indexOf("[") + 1);
            String last = field[field.length - 1];
            field[field.length - 1] = last.substring(0, last.indexOf("]"));


        }
        return field;
    }


    public static String listToString1(List list, char separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i)).append(separator);

        }
        return sb.toString().substring(0, sb.toString().length() - 1);
    }

    public static String substringPrice(String price){
        if (StringUtils.isEmpty(price)){
            return "0";
        }
        String returnPrice = "0";
        if (price.contains(".")){
            return price.substring(0,price.indexOf("."));
        }else {
            return price;
        }
    }



    public static String timeConverter(double inputSeconds){
        int totalSeconds = (int) inputSeconds;  // 取整数部分

        int hours = totalSeconds / 3600;
        int minutes = (totalSeconds % 3600) / 60;
        int seconds = totalSeconds % 60;

        String formattedTime;
        if (hours > 0) {
            formattedTime = String.format("%d:%02d:%02d", hours, minutes, seconds);
        } else {
            formattedTime = String.format("%d:%02d", minutes, seconds);
        }
        return formattedTime;
    }


}
